﻿@using Abp.UI.Inputs
@using humocloud.Editions
@using humocloud.MultiTenancy.Payments.Dto
@model humocloud.Web.Models.TenantRegistration.EditionsSelectViewModel
@{
    ViewBag.DisableTenantChange = true;
    Layout = "_Layout";
}
@section Styles
{
    <link rel="stylesheet" href="~/metronic/4x/css/pricing.min.css" asp-append-version="true" />
    <link href="~/view-resources/Views/TenantRegistration/SelectEdition.css" rel="stylesheet" />
}

<div class="pricing-content-1">
    <div class="row row-centered">
        <!-- Pricing -->

        @{
            var isSetted = false;
        }

        @foreach (var editionWithFeatures in Model.EditionsWithFeatures)
            {
                var edition = editionWithFeatures.Edition;

            <div class="col-lg-3 col-md-6 col-sm-6 col-xs-12 col-centered">
                <div class="price-column-container border-active">
                    <div class="price-table-head m--bg-primary">
                        <h2 class="no-margin">@edition.DisplayName</h2>
                    </div>
                    <div class="arrow-down m--border-top-primary"></div>
                    <div class="price-table-pricing">
                        @if (!edition.AnnualPrice.HasValue && !edition.MonthlyPrice.HasValue)
                        {
                            <div class="row">
                                <div class="col-md-12">
                                    <h4>
                                        @L("Free")
                                    </h4>
                                </div>
                            </div>
                        }
                        else
                        {
                            <div class="row">
                                <div class="col-md-6">
                                    <h4 class="col-md-12">
                                        <sup class="price-sign">$</sup>@edition.MonthlyPrice?.ToString("N2")
                                    </h4>
                                    <p class="col-md-12">@L("PerMonth")</p>
                                </div>
                                <div class="col-md-6">
                                    <h4 class="col-md-12">
                                        <sup class="price-sign">$</sup>@edition.AnnualPrice?.ToString("N2")
                                    </h4>
                                    <p class="col-md-12">@L("PerYear")</p>
                                </div>
                            </div>
                        }
                    </div>
                    <div class="price-table-content">
                        @foreach (var feature in Model.AllFeatures)
                        {
                            var featureValue = editionWithFeatures.FeatureValues.FirstOrDefault(f => f.Name == feature.Name);
                            <div class="row mobile-padding">
                                @if (feature.InputType.GetType() == typeof(CheckboxInputType))
                                {
                                    if (featureValue.Value == "true")
                                    {
                                        <div class="col-xs-3 col-md-2 text-right mobile-padding">
                                            <i class="la la-check-circle m--font-success"></i>
                                        </div>
                                    }
                                    else
                                    {
                                        <div class="col-xs-3 col-md-2 text-right mobile-padding">
                                            <i class="la la-times-circle m--font-danger"></i>
                                        </div>
                                    }
                                    <div class="col-xs-9 col-md-10 text-left mobile-padding edition-description">@feature.DisplayName</div>
                                }
                                else
                                {
                                    <div class="col-xs-3 col-md-2 text-right mobile-padding">
                                        <i class="la la-check-circle m--font-success"></i>
                                    </div>
                                        <div class="col-xs-9 col-md-10 text-left mobile-padding edition-description">@feature.DisplayName: @Html.Raw(featureValue.Value)</div>
                                }
                            </div>
                        }
                    </div>
                    <div class="arrow-down arrow-grey"></div>
                    <div class="price-table-footer">
                        @if (AbpSession.UserId.HasValue)
                        {
                            if (!isSetted)
                            {
                                if (edition.Id == Model.TenantEditionId)
                                {
                                    isSetted = true;
                                }

                                <a class="btn btn-warning" href="#" disabled="disabled">
                                    @L("Upgrade")
                                </a>
                            }
                            else
                            {
                                <a class="btn btn-warning" href="@Url.Action("Upgrade", "Payment", new { upgradeEditionId = edition.Id, editionPaymentType = EditionPaymentType.Upgrade })">
                                    @L("Upgrade")
                                </a>
                            }
                        }
                        else
                        {
                            if (!edition.MonthlyPrice.HasValue && !edition.AnnualPrice.HasValue)
                            {
                                <a class="btn btn-success" href="@Url.Action("Register", "TenantRegistration", new {editionId = edition.Id, subscriptionStartType = SubscriptionStartType.Free})">
                                    @L("Start")
                                </a>
                            }
                            else
                            {
                                if (edition.TrialDayCount.HasValue)
                                {
                                    <a class="btn btn-warning" href="@Url.Action("Register", "TenantRegistration", new {editionId = edition.Id, subscriptionStartType = SubscriptionStartType.Trial})">
                                        @L("FreeTrial")
                                    </a>
                                }

                                <a class="btn btn-info" href="@Url.Action("Buy", "Payment", new {editionId = edition.Id, editionPaymentType = EditionPaymentType.NewRegistration, subscriptionStartType = (int)SubscriptionStartType.Paid})">
                                    @L("BuyNow")
                                </a>
                            }
                        }
                    </div>
                </div>
            </div>
        }
        <!--//End Pricing -->
    </div>
</div>

